import formatters from './index';

describe('UtilsFormatters', () => {
    describe('formatCurrency', () => {
        test('应该正确格式化金额', () => {
            expect(formatters.formatCurrency(1234.56)).toBe('¥1,234.56');
            expect(formatters.formatCurrency(1234.56, '$')).toBe('$1,234.56');
            expect(formatters.formatCurrency(0)).toBe('¥0.00');
        });

        test('应该处理无效输入', () => {
            expect(formatters.formatCurrency(NaN)).toBe('¥0.00');
            expect(formatters.formatCurrency('invalid' as any)).toBe('¥0.00');
        });
    });

    describe('formatDate', () => {
        test('应该正确格式化日期', () => {
            const date = new Date('2023-12-25 15:30:45');
            expect(formatters.formatDate(date)).toBe('2023-12-25');
            expect(formatters.formatDate(date, 'YYYY-MM-DD HH:mm:ss')).toBe('2023-12-25 15:30:45');
        });

        test('应该处理无效日期', () => {
            expect(formatters.formatDate(new Date('invalid'))).toBe('');
            expect(formatters.formatDate('invalid' as any)).toBe('');
        });
    });

    describe('formatFileSize', () => {
        test('应该正确格式化文件大小', () => {
            expect(formatters.formatFileSize(0)).toBe('0 Bytes');
            expect(formatters.formatFileSize(1024)).toBe('1 KB');
            expect(formatters.formatFileSize(1048576)).toBe('1 MB');
        });

        test('应该处理无效输入', () => {
            expect(formatters.formatFileSize(-1)).toBe('0 Bytes');
            expect(formatters.formatFileSize('invalid' as any)).toBe('0 Bytes');
        });
    });

    describe('formatPhoneNumber', () => {
        test('应该正确格式化手机号', () => {
            expect(formatters.formatPhoneNumber('13812345678')).toBe('138 1234 5678');
            expect(formatters.formatPhoneNumber('138-1234-5678')).toBe('138 1234 5678');
        });

        test('应该处理无效手机号', () => {
            expect(formatters.formatPhoneNumber('123')).toBe('123');
            expect(formatters.formatPhoneNumber(123 as any)).toBe('');
        });
    });
});